/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package iteracon.generator.iterator;

import java.util.ListIterator;

/**
 *
 * @author martin
 */
public class FromToListIter implements ListIterator<Integer> {
  private int _from,
              _to,
              _now;

    public FromToListIter(int from, int to, int index){
      _from=from;
      _to=to;
      _now=from+index;
    }
    
    @Override
    public boolean hasNext() {
      return _now+1 < _to;
    }

    @Override
    public Integer next() {
      int tmp = _now;
      _now = _now + 1;
      return tmp;
    }

    @Override
    public void remove() {
      throw new UnsupportedOperationException("Immutable");
    }

  @Override
  public boolean hasPrevious() {
    return _now>_from;
  }

  @Override
  public Integer previous() {
      int tmp = _now;
      _now = _now - 1;
      return tmp;
  }

  @Override
  public int nextIndex() {
    return _now-_from+1;
  }

  @Override
  public int previousIndex() {
    return _now-_from-1;
  }

  @Override
  public void set(Integer e) {
      throw new UnsupportedOperationException("Immutable");
  }

  @Override
  public void add(Integer e) {
      throw new UnsupportedOperationException("Immutable");
  }
}
